package com.sunflower.bath.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.framework.mybatis.Criteria;

import com.sunflower.bath.model.JobNeedExecut;
import com.sunflower.bath.model.JobParams;
import com.sunflower.bath.repository.IJobNeedExecutRepository;
import com.sunflower.bath.service.IJobNeedExecutService;
import com.sunflower.bath.service.IJobParamsService;


public class JobNeedExecutServiceImpl implements IJobNeedExecutService{

  public List<JobNeedExecut> queryPage(Criteria<JobNeedExecut> param){
    List<JobNeedExecut> list = jobNeedExecutRepository.queryPage(param); 
    return list;  }

  public Integer queryPageCount(Criteria<JobNeedExecut> param){
    return (Integer) jobNeedExecutRepository.queryPageCount(param);
  }

  public JobNeedExecut queryEntityById(String id){
    return jobNeedExecutRepository.queryEntityById(id);
  }

  public String insert(JobNeedExecut record){
    int result = jobNeedExecutRepository.insert(record);
    if ( result != 1) { 
      return "要转换成字典常量，新增操作异常。";    } 
    return null;
  }

  public String updateByCriteria(Criteria<JobNeedExecut> param){
    int result = jobNeedExecutRepository.updateByCriteria(param);
    if ( result != 1) { 
      return "要转换成字典常量，修改操作异常。";    } 
    return null;
  }

  public String deleteById(String id){
    int result = jobNeedExecutRepository.deleteById(id);
    if ( result != 1) { 
      return "要转换成字典常量，删除操作异常。";    } 
    return null;
  }

  public String deleteByCriteria(Criteria<JobNeedExecut> param){
    jobNeedExecutRepository.deleteByCriteria(param);
    return null;
  }
  
  public List<JobNeedExecut> queryJobNeedExecut(Criteria<JobNeedExecut> param){
	  List<JobNeedExecut> jobNeedExecutList = jobNeedExecutRepository.queryJobNeedExecut(param);
	  List<JobNeedExecut> jobList = new ArrayList<JobNeedExecut>();
	  for(JobNeedExecut jne:jobNeedExecutList){
		  Criteria<JobParams> jobParamsParam = new Criteria<JobParams>();
		  String jobExecutionId = jne.getJobExecutionId();
		  jobParamsParam.addParam("jobExecutionId", jobExecutionId);
//		  jobParamsParam.setOrderBy(" param_order desc ");
		  jne.setJobParamsList(jobParamsService.queryPage(jobParamsParam));
		  jobList.add(jne);
	  }
	  return jobList;
  }
public void setJobNeedExecutRepository(IJobNeedExecutRepository repository) {this.jobNeedExecutRepository = repository;}
public void setJobParamsService(IJobParamsService jobParamsService) {
	this.jobParamsService = jobParamsService;
}

private IJobNeedExecutRepository jobNeedExecutRepository;
private IJobParamsService jobParamsService;
}
